/*
 * @Author: nns4
 * @Date: 2020-02-17 17:19:14
 * @LastEditors: nns4
 * @FilePath: /rc-app/src/pages/redux/redux-thunk/reduxThunk01/User/actions.js
 * @Description: 
 */

import * as counters from "./const"


export const fetch_user_failure = (error) => {
    return {
        type: counters.FETCH_USER_FAILURE,
        error
    };
};

export const fetch_user = (user) => {
    return {
        type: counters.FETCH_USER_SUCCESS,
        user
    }
};

export const fetch_user_request = () => {
    return {
        type: counters.FETCH_USER_REQUEST
    }
};


export const get_user = () =>{
    return dispatch =>{
        dispatch(fetch_user_request())
        fetch("http://iwenwiki.com/api/blueberrypai/getChengpinDetails.php")
        .then(res => res.json())
        .then(data =>{
            dispatch(fetch_user(data.chengpinDetails[0]))
        })
        .catch(error =>{
            dispatch(fetch_user_failure(error));
        })
    }
}